﻿/*
*idAnaly 0.1
*Copyright (c) 2009 AtHome
*Date:2012-10-24
*轻易解析出id的类型为abc_1或abc_1_1中的数字，获取自身的数字id以及父亲的数字id，获取到的id为整型
*/
(function ($) {
    $.fn.idAnaly_ = function (options) {
        var defaults = {
            cut: "_",//"-",".","|"
            toward: "self"//"father"
        }
        var options = $.extend({}, defaults, options);
        var result = "";
        this.each(function () {
            var oneself = $(this);
            var regexes = [
                new RegExp("(.+)" + options.cut + "(.+)", "g"),
                new RegExp("(.+)" + options.cut + "(.+)" + options.cut + "(.+)", "g")
            ];
            if (options.toward == "self") {
                for (var i in regexes) {
                    if (oneself.attr("id").match(regexes[i])) {
                        result = RegExp.$2;
                    }
                }
            } else if (options.toward == "father") {
                for (var i in regexes) {
                    if (oneself.attr("id").match(regexes[i])) {
                        result = RegExp.$3;
                    }
                }
            } else if (options.toward == "head") {
                for (var i in regexes) {
                    if (oneself.attr("id").match(regexes[i])) {
                        result = RegExp.$1;
                    }
                }
            }
        });
        return result;
    }
})(jQuery);